package com.lc202309;

/**
 * Description: 移动短板 面积发生变化，移动长板，面积一定变小
 *
 * @Create 2023/9/9 21:45
 * @Version 1.0
 */
public class Solution11 {
    public int maxArea1(int[] height) {
        int length = height.length;
        int res = 0;
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                res = Math.max(res, (j - i) * Math.min(height[i], height[j]));
            }
        }
        return res;
    }

    public int maxArea(int[] height) {
        int end = height.length - 1;
        int start = 0;
        int res = 0;
        while (start < end) {
            if (height[start] > height[end]) {
                res = Math.max(res, height[end] * (end - start));
                end--;
                continue;
            }
            res = Math.max(res, height[start] * (end - start));
            start++;
        }
        return res;
    }
}
